#include <stdio.h>
#include "szp_hardware_driver.h"
#include "fatfs_driver.h"
#include "camera_driver.h"
#include "tinyusb_driver.h"
#include "wifi_driver.h"
#include "main_app.h"
#include "button_driver.h"
#include "nvs_driver.h"
#include "ui.h"
#include "screens.h"

#include "dirent.h"
#include "my_ui_api.h"
#include "web_app.h"

extern "C" void app_main(void)
{
    nvs_init();

    bsp_i2c_init();   // I2C初始化
    pca9557_init();   // IO扩展芯片初始化
    bsp_lvgl_start(); // 初始化液晶屏lvgl接口
    fatfs_init();
    // tinyusb_start();
    // while (1)
    // {
    //     vTaskDelay(pdMS_TO_TICKS(1000));
    // }
    
#if 0
    wifi_init(WIFI_MODE_STA, false);
    wifi_connect((uint8_t *)STA_SSID, (uint8_t *)STA_PASSWORD);
#include "web_server_driver.h"
    web_server_init();
    while (1)
    {
        vTaskDelay(pdMS_TO_TICKS(1000));
    }
#endif

    lvgl_port_lock(0);
    ui_init();
    lvgl_port_unlock();

    int32_t mode = nvs_read("mode_space","mode_key");
    if (mode)
        main_task_start();
    else
        web_task_start();

    while (1)
    {
        lvgl_port_lock(0);
        ui_tick();
        lvgl_port_unlock();
        vTaskDelay(pdMS_TO_TICKS(20));
    }
}
